package com.cet.designpatterns.principle.dependenceinversion.improvement;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-26 17:16
 **/
public class DependencyInversion {
    public static void main(String[] args) {
        Person person = new Person();
        //客户端无需改变
        person.receive(new Email());

        person.receive(new WeiXin());
    }
}

/**
 *定义一个接口
 */
interface IReceiver{
    String getInfo();
}

class Person{
    public void receive(IReceiver receiver) {
        System.out.println(receiver.getInfo());
    }
}

class Email implements IReceiver{
    @Override
    public String getInfo() {
        return "电子邮件信息：hello, design patterns!";
    }
}

class WeiXin implements IReceiver{
    @Override
    public String getInfo() {
        return "微信消息：滴滴！";
    }
}
